package com.winshare.saleAssistant.controller;


import com.winshare.saleAssistant.model.OrgManagement;
import com.winshare.saleAssistant.model.OrgManagementLog;
import com.winshare.saleAssistant.service.BannerService;
import com.winshare.saleAssistant.service.IOrgManagementLogService;
import com.winshare.saleAssistant.service.IOrgManagementService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Donie
 */
@RestController
@RequestMapping("/sys/orgManagement")
@CrossOrigin
@Api(value = "供应商接口管理")
public class OrgManagementController {

    @Autowired
    private IOrgManagementService orgManagementService;

    @Autowired
    private IOrgManagementLogService orgManagementLogService;

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list() {
        List<OrgManagement> orgManagements = orgManagementService.list(null);
        return LogicResponse.success(orgManagements);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(OrgManagement orgManagement) {
        orgManagementService.save(orgManagement);
        return LogicResponse.success("success");
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer orgManagementId) {
        orgManagementService.removeById(orgManagementId);
        return LogicResponse.success("success");
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(OrgManagement orgManagement) {
        orgManagementService.updateById(orgManagement);
        return LogicResponse.success("success");
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{orgManagementId}")
    @ResponseBody
    public Object detail(@PathVariable("orgManagementId") Integer orgManagementId) {
        return LogicResponse.success(orgManagementService.getById(orgManagementId));

    }

    @RequestMapping(value = "/selectLog")
    @ResponseBody
    public Object selectLog(Integer id) {
        List<OrgManagementLog> orgManagementLogs = orgManagementLogService.selByOid(id);
        return LogicResponse.success(orgManagementLogs);
    }

    @RequestMapping(value = "/selresult")
    @ResponseBody
    public Object selectResult(Integer id) {
        OrgManagementLog orgManagementLog = orgManagementLogService.selById(id);
        return LogicResponse.success(orgManagementLog);
    }
}
